<?php
include_once("dbconnect/db.php");
include_once("Common.php");
Class redirect
{
	static public function adClick($adid,$type_c)
	{
		$common = new Common;
		$common->initCarrierInfo();
		$uid = $common->uId;
		$carrierId = $common->carrierId ;
		//echo "uid:".$uid." carid:".$carrierId;
		if($uid == "") return;
		
		
		$sql = "select memberId
		       from memberMst 
			   Where uim='$uid'";
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		
		if($rows > 0 )
		{
			$sql = "Update memberMst set adspace_id=$adid,adclick_date=now(),type_c=$type_c
		        Where uim='$uid'";
			//echo $sql;
			mysql_query($sql);
		}
		else
		{
			$sql = "Insert memberMst(
			carrierId,uim,adspace_id,adclick_date,lastlogin_date,type_c)
			values($carrierId,'$uid',$adid,now(),now(),$type_c)";
			//echo $sql;
			mysql_query($sql);
		}
		
	}
	
	static public function getLinkById($adid)
	{
		$sql = "select core_link
		       from adspace_mst 
			   where adspace_id =$adid";
		$resultAd = mysql_query($sql);
		$rowsAd = mysql_num_rows($resultAd);
		if($rowsAd == 0 ) return "top_page.php";
		
		$row = mysql_fetch_array($resultAd);
		return "$row[0]";
	}
	
}
?>